from . import BlockRegistry, BlockType
from dataclasses import dataclass

from Utils import logger

# 物品注册存放表
ItemRegistry = {}


@dataclass
class ItemData:
    block_type: BlockType = None  # 方块类型
    name: str = ''
    ids: int = 0
    texture_id: int = 0
    display_type: int = 0
    block_id: int = -1
    item_texture_uv = None

    def __post_init__(self):
        self.name = self.block_type.name
        self.ids = self.block_type.value
        self.texture_id = self.block_type.value

        self.item_texture_uv = BlockRegistry[self.texture_id].texture_id[0]
        # display_type: 0: 物品以图标显示，1: 物品以方块显示

        ItemRegistry[self.ids] = self  # 注册到全局表


# 注册方块对应的物品
ItemList = [
    ItemData(BlockType.Air),
    ItemData(BlockType.Grass),
    ItemData(BlockType.Dirt),
    ItemData(BlockType.Log),
    ItemData(BlockType.Leave),
    ItemData(BlockType.SnowyGrass),
    ItemData(BlockType.DiamondBlock),
    ItemData(BlockType.Wood),
    ItemData(BlockType.Glass),
    ItemData(BlockType.Wool),
    ItemData(BlockType.CobbleStone),
    ItemData(BlockType.MossyCobbleStone),
    ItemData(BlockType.TNT),
    ItemData(BlockType.CraftingTable),
    ItemData(BlockType.DarkLog),
    ItemData(BlockType.HayBlock),
    ItemData(BlockType.Podzol),
    ItemData(BlockType.Sand),
    ItemData(BlockType.SandStone),
    ItemData(BlockType.BirchLog),
    ItemData(BlockType.Stone),
    ItemData(BlockType.Poppy),
    ItemData(BlockType.Allium),
    ItemData(BlockType.AzureBluet),
    ItemData(BlockType.Dandelion),
    ItemData(BlockType.Straw),
]
logger.info(f'已注册{len(ItemRegistry)}个物品')
